define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'file/pet/index' + location.search,
                    add_url: 'file/pet/add',
                    edit_url: 'file/pet/edit',
                    del_url: 'file/pet/del',
                    multi_url: 'file/pet/multi',
                    import_url: 'file/pet/import',
                    table: 'pet',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                exportTypes:['excel'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('Name'),operate: 'LIKE %...%', placeholder: '模糊搜索'},
                        {field: 'class', title: __('Class'),operate: false,visible:false},
                        {field: 'catch_level', title: __('Catch_level'),operate: 'RANG',},
                        {field: 'group', title: __('Group'),operate: false,visible:false},
                        {field: 'is_varition', title: __('Is_varition'),operate: false},
                        {field: 'is_baby', title: __('Is_baby'),operate: false},
                        {field: 'food_type', title: __('Food_type'),operate: false},
                        {field: 'skill_study', title: __('Skill_study'),operate: false,visible:false},
                        {field: 'positive_skill_one', title: __('Positive_skill_one'),operate: false,visible:false},
                        {field: 'positive_skill_one_percent', title: __('Positive_skill_one_percent'),operate: false,visible:false},
                        {field: 'positive_skill_two', title: __('Positive_skill_two'),operate: false,visible:false},
                        {field: 'positive_skill_two_percent', title: __('Positive_skill_two_percent'),operate: false,visible:false},
                        {field: 'negative_skill_one', title: __('Negative_skill_one'),operate: false,visible:false},
                        {field: 'negative_skill_one_percent', title: __('Negative_skill_one_percent'),operate: false,visible:false},
                        {field: 'negative_skill_two', title: __('Negative_skill_two'),operate: false,visible:false},
                        {field: 'negative_skill_two_percent', title: __('Negative_skill_two_percent'),operate: false,visible:false},
                        {field: 'negative_skill_three', title: __('Negative_skill_three'),operate: false,visible:false},
                        {field: 'negative_skill_three_percent', title: __('Negative_skill_three_percent'),operate: false,visible:false},
                        {field: 'negative_skill_four', title: __('Negative_skill_four'),operate: false,visible:false},
                        {field: 'negative_skill_four_percent', title: __('Negative_skill_four_percent'),operate: false,visible:false},
                        {field: 'negative_skill_five', title: __('Negative_skill_five'),operate: false,visible:false},
                        {field: 'negative_skill_five_percent', title: __('Negative_skill_five_percent'),operate: false,visible:false},
                        {field: 'negative_skill_six', title: __('Negative_skill_six'),operate: false,visible:false},
                        {field: 'negative_skill_six_percent', title: __('Negative_skill_six_percent'),operate: false,visible:false},
                        {field: 'negative_skill_seven', title: __('Negative_skill_seven'),operate: false,visible:false},
                        {field: 'negative_skill_seven_percent', title: __('Negative_skill_seven_percent'),operate: false,visible:false},
                        {field: 'negative_skill_eight', title: __('Negative_skill_eight'),operate: false,visible:false},
                        {field: 'negative_skill_eight_percent', title: __('Negative_skill_eight_percent'),operate: false,visible:false},
                        {field: 'negative_skill_nine', title: __('Negative_skill_nine'),operate: false,visible:false},
                        {field: 'negative_skill_nine_percent', title: __('Negative_skill_nine_percent'),operate: false,visible:false},
                        {field: 'negative_skill_ten', title: __('Negative_skill_ten'),operate: false,visible:false},
                        {field: 'negative_skill_ten_percent', title: __('Negative_skill_ten_percent'),operate: false,visible:false},
                        {field: 'basic_hp', title: __('Basic_hp'),operate: false,visible:false},
                        {field: 'basic_str', title: __('Basic_str'),operate: false,visible:false},
                        {field: 'basic_con', title: __('Basic_con'),operate: false,visible:false},
                        {field: 'basic_spr', title: __('Basic_spr'),operate: false,visible:false},
                        {field: 'basic_dex', title: __('Basic_dex'),operate: false,visible:false},
                        {field: 'basic_com', title: __('Basic_com'),operate: false,visible:false},
                        {field: 'grow_rate_one', title: __('Grow_rate_one'),operate: false,visible:false},
                        {field: 'grow_rate_two', title: __('Grow_rate_two'),operate: false,visible:false},
                        {field: 'grow_rate_three', title: __('Grow_rate_three'),operate: false,visible:false},
                        {field: 'grow_rate_four', title: __('Grow_rate_four'),operate: false,visible:false},
                        {field: 'grow_rate_five', title: __('Grow_rate_five'),operate: false,visible:false},
                        {field: 'timid', title: __('Timid'),operate: false,visible:false},
                        {field: 'cautious', title: __('Cautious'),operate: false,visible:false},
                        {field: 'loyal', title: __('Loyal'),operate: false,visible:false},
                        {field: 'shrewd', title: __('Shrewd'),operate: false,visible:false},
                        {field: 'bravery', title: __('Bravery'),operate: false,visible:false},
                        {field: 'breeding_time', title: __('Breeding_time'),operate: false,visible:false},
                        {field: 'same_type', title: __('Same_type'),operate: false,visible:false},
                        {field: 'extra_one', title: __('Extra_one'),operate: false,visible:false},
                        {field: 'extra_two', title: __('Extra_two'),operate: false,visible:false},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: '操作',
                            table: table,
                            operate:false,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '详情',
                                    title:'详情',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'file/pet/detail',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: true
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});